<template>
    <!-- <a-input v-model="model.templateContext" placeholder="请输入模板内容" ></a-input> -->
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="参数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parameterName">
                <j-popup
                  v-model="model.parameterName"
                  field="parameterId"
                  org-fields="id,parameter_name"
                  dest-fields="parameterId,parameterName"
                  code="plcParamQuery"
                  :param="popParam"
                  :multi="true"
                  @input="popupCallback"
                  />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="参数类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parameterType">
                <j-dict-select-tag type="list" v-model="model.parameterType" dictCode="parameter_type" placeholder="请选择参数类别" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationNumber">
                <a-input v-model="model.locationNumber" placeholder="请输入位号"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="配置人员角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="configRoles">
                <a-input v-model="model.configRoles" placeholder="请输入配置人员角色"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="实际参数取值范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parameterActualRange">
                <a-input v-model="model.parameterActualRange" placeholder="请输入实际参数取值范围"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="控件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlType">
                <a-input v-model="model.controlType" placeholder="请输入控件类型"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="控件值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlValue">
                <a-input v-model="model.controlValue" placeholder="请输入控件值"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="是否必填" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlRequired">
                <a-input v-model="model.controlRequired" placeholder="请输入是否必填"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </template>
  
  <script>
  
    import { httpAction, getAction } from '@/api/manage'
    import { validateDuplicateValue } from '@/utils/util'
  
    export default {
      name: 'YksEquipmentConfigurationPlcForm',
      components: {
      },
      props: {
        //表单禁用
        disabled: {
          type: Boolean,
          default: false,
          required: false
        }
      },
      data () {
        return {
          model:{
           },
          labelCol: {
            xs: { span: 24 },
            sm: { span: 5 },
          },
          wrapperCol: {
            xs: { span: 24 },
            sm: { span: 16 },
          },
          confirmLoading: false,
          currentEquipmentId:'',
          validatorRules: {
          },
          popParam:{plc_model:'1'},
          url: {
            add: "/dev/yksEquipmentConfigurationPlc/add",
            edit: "/dev/yksEquipmentConfigurationPlc/edit",
            queryById: "/dev/yksEquipmentConfigurationPlc/queryById"
          }
        }
      },
      computed: {
        formDisabled(){
          return this.disabled
        },
      },
      created () {
         //备份model原始值
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
      },
      methods: {
        add () {
          this.edit(this.modelDefault);
        },
        edit (record) {
          this.model = Object.assign({}, record);
          this.model.equipmentId = this.currentEquipmentId
          this.visible = true;
        },
        submitForm () {
          const that = this;
          // 触发表单验证
          this.$refs.form.validate(valid => {
            if (valid) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
              }else{
                httpurl+=this.url.edit;
                 method = 'put';
              }
              httpAction(httpurl,this.model,method).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.$emit('ok');
                }else{
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              })
            }
           
          })
        },
        popupCallback(value,row){
           this.model = Object.assign(this.model, row);
        },
      }
    }
  </script>